﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.Core.Admin;
using Jzy.Core.Utility;

namespace ECommerce.Web
{
    public partial class Login : System.Web.UI.Page
    {
        private UserBO user = new UserBO();
       
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        protected void btnLogin_Click(object sender, ImageClickEventArgs e)
        {

            string strLoginName = txtLoginName.Text.Trim();
            string strPassword = txtPassword.Text.Trim();


            CheckLogin(strLoginName, strPassword);

        }

        private void CheckLogin(string strLoginName, string strPassword)
        {           

            LoginResult result = user.CheckLogin(strLoginName, strPassword);

            bool blnFlag = true;
            switch (result)
            {
                case LoginResult.Forbidden:
                case LoginResult.PwdErr:
                case LoginResult.UserErr:
                    blnFlag = false;
                    break;
            }

            if (blnFlag)
            {
                user.SetSession(strLoginName);               
                string strUrl = "common/frame/default.aspx";               
                Response.Redirect(strUrl);
            }
            else
            {                
                JSUtil.Alert("用户名或密码错！");
            }

            
        }
    }
}